class Solution {
public:
    double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        long long m = n;
        return n < 0 ? 1 / pow(x, -m) : pow(x, m);
    }

    double pow(double x, long long n) {
        if (n == 1) {
            return x;
        }
        else {
            double tmp = myPow(x, n / 2);
            tmp *= tmp;
            return n % 2 == 0 ? tmp : tmp * x;
        }
    }
};